package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.PeoductInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.PeoductInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.client.PeoductInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 公司产品信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "peoductInfo", description = "公司产品信息")
@RestController
@RequestMapping("/peoductInfo")
public class PeoductInfoController{

    @Reference(version = "${service.version}", check = false)
    PeoductInfoService peoductInfoService;

    @RateLimit()
    @ApiOperation("产品信息")
    @PostMapping("/seletePeoductInfo")
    public ResultVo seletePeoductInfo(@RequestBody PeoductInfoDto callAplanInfoDto){
        PageInfo<PeoductInfo> list = peoductInfoService.seletePeoductInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新产品信息")
    @PostMapping("/updatePeoductInfo")
    public ResultVo updatePeoductInfo(@ApiParam(value = "callAplanInfoDto", required = true)
                                      @Validated @RequestBody PeoductInfo callAplanInfoDto){
        boolean index = peoductInfoService.updatePeoductInfo(callAplanInfoDto);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加产品信息")
    @PostMapping("/addPeoductInfo")
    public ResultVo addPeoductInfo(@ApiParam(name = "callAplanInfo", required = false)
                                   @Validated @RequestBody PeoductInfo callAplanInfo){
        boolean list  = peoductInfoService.addPeoductInfo(callAplanInfo);
        return  ResultVo.success(list);
    }


    @RateLimit()
    @ApiOperation("删除产品信息")
    @DeleteMapping("deletePeoductInfo/{proId}")
    public ResultVo deletePeoductInfo(@NotNull @ApiParam(name = "proId", value = "proId", required = true) @PathVariable String proId){
        boolean b = peoductInfoService.removePeoductInfo(proId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}